package com.sky.controller.User;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "c-购物车")
public class ShoppingController {
    @Autowired
    private ShoppingService shoppingService;
    /*
    * 添加购物车
    * */
    @PostMapping("/add")
    @ApiOperation("购物车添加")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
            shoppingService.shoppingadd(shoppingCartDTO);
            return Result.success();
    }
    /*
    * 查询购物车
    * */
    @GetMapping("/list")
    @ApiOperation("查询购物车")
    public Result<List<ShoppingCart>> select(){
     List<ShoppingCart> list =  shoppingService.select();
     return Result.success(list);
    }
    /*
    * 清空购物车
    *
    * */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result cleanShopping(){
        shoppingService.shoppingdclean();
        return Result.success();
    }
    /*
    * 根据Uid删除商品货套餐
    * */
@PostMapping("/sub")
@ApiOperation("根据id删除购物车商品")
    public Result shoppingsub(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingService.subshopping(shoppingCartDTO);
        return Result.success();
}
}

